package com.sgq.entity;

import com.baomidou.mybatisplus.annotation.*;

import java.time.LocalDateTime;
import java.io.Serializable;
import java.util.Collection;
import java.util.List;

import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

/**
 * <p>
 * 
 * </p>
 *
 * @author sgq
 * @since 2024-09-13
 */
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("sys_user")
public class User extends MyBaseEntity implements UserDetails {

    /**
     * 登录名称(用户名)
     */
    private String username;

    /**
     * 登录密码
     */
    private String password;

    /**
     * 帐户是否过期(1-未过期，0-已过期)
     */
    @TableField(fill = FieldFill.INSERT)
    private Integer isAccountNonExpired;

    /**
     * 帐户是否被锁定(1-未过期，0-已过期)
     */
    @TableField(fill = FieldFill.INSERT)
    private Integer isAccountNonLocked;

    /**
     * 密码是否过期(1-未过期，0-已过期)
     */
    @TableField(fill = FieldFill.INSERT)
    private Integer isCredentialsNonExpired;

    /**
     * 帐户是否可用(1-可用，0-禁用)
     */
    @TableField(fill = FieldFill.INSERT)
    private Integer isEnabled;

    /**
     * 真实姓名
     */
    private String realName;

    /**
     * 昵称
     */
    private String nickName;

    /**
     * 所属部门ID
     */
    private Long departmentId;

    /**
     * 所属部门名称
     */
    private String departmentName;

    /**
     * 性别(0-男，1-女)
     */
    private Integer gender;

    /**
     * 电话
     */
    private String phone;

    /**
     * 邮箱
     */
    private String email;

    /**
     * 用户头像
     */
    private String avatar;

    /**
     * 是否是管理员(1-管理员)
     */
    private Integer isAdmin;

    /**
     * 权限列表
     */
    @TableField(exist = false)
    Collection<? extends GrantedAuthority> authorities;

    /**
     * 菜单列表
     */
    @TableField(exist = false)
    private List<Permission> permissions;


    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return this.authorities;
    }

    @Override
    public boolean isAccountNonExpired() {
        System.out.println("《判断账户是否过期》");
        return this.isAccountNonExpired == 1;
    }

    @Override
    public boolean isAccountNonLocked() {
        System.out.println("《判断账户是否锁定》");
        return this.isAccountNonLocked == 1;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        System.out.println("《判断密码是否超时》");
        return this.isCredentialsNonExpired == 1;
    }

    @Override
    public boolean isEnabled() {
        System.out.println("《判断账户是否可用》");
        return this.isEnabled == 1;
    }
}
